package com.yanqu.road.server.cmd.activity.sonhai;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SonHaiProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiActivity;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C2_SON_HAI_ACCEPT_OCCUPY_EGG_BE_TAKEN_MSG, desc = "山海伏兽-接收到占领的蛋被抢")
public class CrossSonHaiAcceptOccupyEggBeTakenMsgCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        SonHaiProto.SonHaiAcceptOccupyEggBeTakenMsgReqMsg reqMsg = SonHaiProto.SonHaiAcceptOccupyEggBeTakenMsgReqMsg.parseFrom(packet.getBytes());
        SonHaiProto.SonHaiAcceptOccupyEggBeTakenMsgRespMsg.Builder respMsg = SonHaiProto.SonHaiAcceptOccupyEggBeTakenMsgRespMsg.newBuilder();
        CrossSonHaiActivity activity = CrossSonHaiActivityMgr.getActivity(reqMsg.getActivityId(), groupId);
        if (activity == null) {
            respMsg.setRet(GameErrorCode.E_SON_HAI_ACTIVITY_NOT_FOUND);
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_SON_HAI_ACCEPT_OCCUPY_EGG_BE_TAKEN_MSG, respMsg));
            return;
        }
        //接收到占领的蛋被抢
        try {
            //接收到占领的蛋被抢
            activity.acceptOccupyEggBeTakenMsg(packet.getPlayerId(), reqMsg.getEggIdsList());
            respMsg.setRet(0);
        } catch (BusinessException e) {
            respMsg.setRet(e.getCode());
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_SON_HAI_ACCEPT_OCCUPY_EGG_BE_TAKEN_MSG, respMsg));
    }

    @Override
    public void sendData() {

    }
}
